﻿using FastReport.Design;
using ICSharpCode.SharpZipLib.Checksum;
using ICSharpCode.SharpZipLib.Zip;
using iTextSharp.text.pdf;
using Kingdee.BOS.Util;
using LanDBom.Models;
using LanDBom.Models.Contracts;
using LanDBom.Models.Entity;
using LanDBom.Models.Procure;
using LanDBom.Models.Technology;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Utilities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Reflection;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using System.Web.WebPages;
using static System.Net.Mime.MediaTypeNames;


namespace LanDBom.Controllers
{
    public class ContractsController : Controller
    {
        LDbaseEntities db = new LDbaseEntities();
        // GET: Contracts
        Modlfy_Contracts MC = new Modlfy_Contracts();
        AddContracts AC = new AddContracts();
        Find_Contracts FC = new Find_Contracts();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Design_order(string DTon = "", int state = -99, string APP_bian = null)
        {
            var shunji = db.Dengli.ToList();

            ViewBag.res = shunji;

            Session["names_DTon"] = DTon;

            if (state == 1)
            {
                var listcon = FC.find_Contracts(DTon);
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(listcon, settings);
                return Content(jsongStr, "application/json");

            }
            else if (state == -99 && DTon != null)
            {
                return View();
            }
            else if (state == 2)
            {
                var listde = FC.find_Design();
                var Listbom = FC.find_Boms(DTon);
                var temp = from a in Listbom
                           join b in listde on a.BOM2_id equals b.BOM2_id into c
                           from d in c.DefaultIfEmpty()
                           select new { a.BOM2_wuLiu, a.BOM2_liao, a.BOM2_Guige, a.BOM2_chen, a.BOM2_id, De_ren = d == null ? " " : d.De_ren, DE_JDR = d == null ? " " : d.DE_JDR, BOM2_sunhao = a == null ? "" : a.BOM2_sunhao };

                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(temp, settings);
                return Content(jsongStr, "application/json");
            }
            return View();
        }
        public ActionResult find_Client_name(string name)
        {
            var listcl = FC.find_Client_name(name);
            JsonSerializerSettings settings = new JsonSerializerSettings();
            string jsongStr = JsonConvert.SerializeObject(listcl, settings);

            return Content(jsongStr, "application/json");
        }

        public ActionResult Temporary_storage(Designdraw designdraw)
        {
            int temp = db.Designdraw.Where(x => x.D_Ton == designdraw.D_Ton).Count();
            if (temp > 0)
            {
                Designdraw des = db.Designdraw.Where(x => x.D_Ton == designdraw.D_Ton).FirstOrDefault();
                if (designdraw.D_zhuang == null)
                {
                    designdraw.D_zhuang = des.D_zhuang;
                }
                des.D_Applic = designdraw.D_Applic;
                des.D_reDate = designdraw.D_reDate;
                des.D_price = designdraw.D_price;
                des.D_take = designdraw.D_take;
                des.D_App = designdraw.D_App;
                des.D_AppRevi = designdraw.D_AppRevi;
                des.D_Ton = designdraw.D_Ton;
                des.D_CN = designdraw.D_CN;
                des.D_PN = designdraw.D_PN;
                des.D_DE = designdraw.D_DE;
                des.D_LV = designdraw.D_LV;
                des.D_DT = designdraw.D_DT;
                des.D_PW = designdraw.D_PW;
                des.D_SI = designdraw.D_SI;
                des.D_OI = designdraw.D_OI;
                des.D_MOF = designdraw.D_MOF;
                des.D_PT = designdraw.D_PT;
                des.D_PR = designdraw.D_PR;
                des.D_OR = designdraw.D_OR;
                des.D_SR = designdraw.D_SR;
                des.D_PA = designdraw.D_PA;
                des.D_REC = designdraw.D_REC;
                des.D_AR = designdraw.D_AR;
                des.D_CD = designdraw.D_CD;
                des.D_TCA = designdraw.D_TCA;
                des.D_dhr = designdraw.D_dhr;
                des.D_dhly = designdraw.D_dhly;
                des.D_zhuang = designdraw.D_zhuang;
                db.Entry(des).State = EntityState.Modified;
                int rows = db.SaveChanges();
                string message = rows > 0 ? "修改成功" : "修改失败";
                return Content(message, "text / plain");
            }
            else if (temp >= 0)
            {
                var jinslp = designdraw.D_Ton;
                var sjnd = UpdateAPP(jinslp);
                int rows = AC.Adddes(designdraw);
                string message = rows > 0 ? "添加成功" : "添加失败";
                return Content(message, "text / plain");
            }
            return View();
        }

        public ActionResult Temporary_storage2(Designdraw designdraw)
        {
            Designdraw des = db.Designdraw.Where(x => x.D_Ton == designdraw.D_Ton).FirstOrDefault();
            des.D_zhuang = designdraw.D_zhuang;
            des.D_dhr = designdraw.D_dhr;
            designdraw.D_dhly = designdraw.D_dhly;
            int rows = db.SaveChanges();
            //删除历史记录
            if (rows > 0)
            {
                var SHeji = db.ShejinBeiZhu.Where(s => s.SJ_Bian == designdraw.D_Ton).ToList();
                foreach (var item in SHeji)
                {
                    db.ShejinBeiZhu.Remove(item);
                    db.SaveChanges();
                }
            }
            string message = rows > 0 ? "1" : "0";
            return Content(message, "text / plain");
        }

        public ActionResult Design_Update_end(Designdraw designdraw)
        {
            Designdraw des = db.Designdraw.Where(x => x.D_Ton == designdraw.D_Ton).FirstOrDefault();
            des.D_zhuang = designdraw.D_zhuang;
            des.D_dhr = designdraw.D_dhr;
            designdraw.D_dhly = designdraw.D_dhly;
            int rows = db.SaveChanges();
            string message = rows > 0 ? "修改成功" : "修改失败";
            return Content(message, "text / plain");
        }

        public ActionResult Temporary_storage3(Designdraw designdraw)
        {
            Designdraw des = db.Designdraw.Where(x => x.D_Ton == designdraw.D_Ton).FirstOrDefault();
            des.D_AppRevi = designdraw.D_AppRevi;
            int rows = db.SaveChanges();
            string message = rows > 0 ? "修改成功" : "修改失败";
            return Content(message, "text / plain");
        }
        public ActionResult Append_Contracts20(string Shun = "", string Ton = "")
        {
            Designdraw des = db.Designdraw.Where(x => x.D_Ton == Ton).FirstOrDefault();
            des.D_zhuang = Shun;
            int rows = db.SaveChanges();
            string message = rows > 0 ? "修改成功" : "修改失败";
            return Content(message, "text / plain");
        }
        public ActionResult changeAPP_BOhui(Applications designdraw)
        {
            Applications des = db.Applications.Where(x => x.AP_bian == designdraw.AP_bian).FirstOrDefault();
            des.APP_liy = designdraw.APP_liy;
            des.APP_shr = designdraw.APP_shr;
            des.APP_liy = designdraw.APP_liy;
            des.App_zhuang = designdraw.App_zhuang;

            int rows = db.SaveChanges();
            if (rows == 1)
            {
                var shhn = new BeiZhu()
                {
                    B_Bian = designdraw.AP_bian,
                    B_bei = designdraw.APP_liy,
                    B_BR = designdraw.APP_shr,
                    B_Date = DateTime.Now.ToString("yyyy-M-d")
                };
                db.BeiZhu.Add(shhn);
                db.SaveChanges();
            }
            string message = rows > 0 ? "修改成功" : "修改失败";
            return Content(message, "text / plain");
        }
        public ActionResult Submit(Edit_Contracts designdraw)
        {
            var jinslp = designdraw.D_Ton;
            var sjnd = UpdateAPP(jinslp);
            Designdraw des = new Designdraw()
            {
                D_Applic = designdraw.D_Applic,
                D_reDate = designdraw.D_reDate,
                D_take = designdraw.D_take,
                D_App = designdraw.D_App,
                D_AppRevi = designdraw.D_AppRevi,
                D_Ton = designdraw.D_Ton,
                D_CN = designdraw.D_CN,
                D_PN = designdraw.D_PN,
                D_DE = designdraw.D_DE,
                D_LV = designdraw.D_LV,
                D_DT = designdraw.D_DT,
                D_PW = designdraw.D_PW,
                D_SI = designdraw.D_SI,
                D_OI = designdraw.D_OI,
                D_MOF = designdraw.D_MOF,
                D_PT = designdraw.D_PT,
                D_PR = designdraw.D_PR,
                D_OR = designdraw.D_OR,
                D_SR = designdraw.D_SR,
                D_PA = designdraw.D_PA,
                D_REC = designdraw.D_REC,
                D_AR = designdraw.D_AR,
                D_CD = designdraw.D_CD,
                D_TCA = designdraw.D_TCA,
                D_zhuang = designdraw.D_zhuang,
                D_dhr = designdraw.D_dhr,
                D_dhly = designdraw.D_dhly,
                D_price = designdraw.D_price.AsDecimal()
            };
            int rows = MC.EditDes(des);
            string message = rows > 0 ? "修改成功" : "修改失败";
            return Content(message, "text / plain");
        }
        //申请单为纯设计时修改设计单
        public string UpdateAPP(string snhuan)
        {
            string message = "";
            var appent = db.Applications.FirstOrDefault(s => s.AP_bian == snhuan);
            var zhand = appent == null ? "0" : appent.App_zhand;
            if (zhand == "3" && appent.App_bei != "保存")
            {
                appent.App_bu = "2";
                db.Entry(appent).State = EntityState.Modified;
                int jins = db.SaveChanges();
                message = jins > 0 ? "1" : "2";//1--成功，2--失败
            }
            else
            {
                message = "1";
            }
            return message;
        }

        public ActionResult find_Contracts(string D_Ton)
        {
            int index = FC.find_Contracts_with_D_Ton(D_Ton);
            string message = index > 0 ? "申请单已存在" : "无此申请单号";
            return Content(message, "text / plain");
        }

        public ActionResult Inspect_Contracts(int D_ID = -99, string D_Applic = "", string D_Ton = "", int state = 0, string BB_SQ_xmmc = null, string BB_SQ_khmc = null, string BB_SQ_sqrq = null, string BB_SQ_gjz = null, string jssj = null, string qssj = null, string danhao = null, string xmlx = null, int Namess = 0, int shunfl = 0, int JIN = 0, string id = "")
        {
            if (state == 1)
            {
                var ListDesB = FC.find_Contracts_bao(BB_SQ_xmmc, BB_SQ_khmc, BB_SQ_gjz, jssj, qssj, danhao, xmlx, Namess, JIN);
                var denglu = db.Dengli.Where(s => s.DE_ID == Namess).FirstOrDefault();
                if (denglu.DE_bumeng == 2)
                {
                    ListDesB = ListDesB.Where(s => s.D_zhuang != "5" && s.D_zhuang != "4" && s.D_zhuang != "-99" && s.D_zhuang != "1").ToList();
                }
                ListDesB = ListDesB.Skip(shunfl * 10).Take(10).ToList();
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(ListDesB, settings);
                return Content(jsongStr, "application/json");
            }
            else if (state == 2)
            {
                var ListDesB = FC.find_Contracts_bao(D_ID);
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(ListDesB, settings);
                return Content(jsongStr, "application/json");
            }
            else if (state == 3)
            {
                if (id != "")
                {
                    var sjn = int.Parse(id);
                    var shukm = db.Applications.FirstOrDefault(s => s.App_id == sjn);
                    if (shukm != null)
                    {
                        D_Ton = shukm.AP_bian;
                    }
                }
                var list = db.ShejinBeiZhu.Where(x => x.SJR_id == D_ID && x.SJ_Bian == D_Ton).ToList();
                var temp = from a in list
                           select new { a.SJ_Bian, a.SJ_ZT };
                JsonSerializerSettings settings = new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    Formatting = Formatting.Indented
                };
                string jsongStr = JsonConvert.SerializeObject(list, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 4)
            {
                string temp = "";
                ShejinBeiZhu sjbz = db.ShejinBeiZhu.Where(x => x.SJ_Bian == D_Ton && x.SJR_id == D_ID).FirstOrDefault();
                if (sjbz != null)
                {
                    if (sjbz.SJ_ZT == "完成")
                    {
                        temp = "完成";
                    }
                    else
                    {
                        temp = "未完成";
                    }
                }
                return Content(temp);
            }
            else if (state == 5)
            {
                int l1 = db.ShejinBeiZhu.Where(x => x.SJ_Bian == D_Ton).Count();
                int l2 = db.ShejinBeiZhu.Where(x => x.SJ_Bian == D_Ton && x.SJ_ZT == "完成").Count();
                string temp = "";
                if (l2 > 0)
                {
                    temp = l2 + "/" + l1 + "设计人员已递交";
                }
                else
                {
                    temp = "设计人员设计中";
                }
                return Content(temp);
            }
            else if (state == 6)
            {
                var bh = db.BoHUijl.Where(s => s.BH_appbian == D_Ton).ToList();
                JsonSerializerSettings settings = new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    Formatting = Formatting.Indented
                };
                string jsongStr = JsonConvert.SerializeObject(bh, settings);
                return Content(jsongStr, "application/json");
            }
            else if (state == 7)
            {
                string zhuang = "";
                int count = 0;
                if (JIN == 2)
                {
                    count = db.ShejinBeiZhu.Where(x => x.SJR_id == D_ID && x.SJ_Bian == D_Ton && x.SJ_ZT != "完成").Count();
                }
                else if (JIN == 1)
                {
                    count = db.ShejinBeiZhu.Where(x => x.SJR_id == D_ID && x.SJ_Bian == D_Ton && x.SJ_ZT == "完成").Count();
                }
                if (count == 0)
                {
                    zhuang = "不添加";
                }
                else
                {
                    zhuang = "添加";
                }
                return Content(zhuang);
            }
            else if (state == 8)
            {
                var ListDesB = FC.find_Contracts_bao(BB_SQ_xmmc, BB_SQ_khmc, BB_SQ_gjz, jssj, qssj, danhao, xmlx, Namess, JIN);
                var denglu = db.Dengli.Where(s => s.DE_ID == Namess).FirstOrDefault();
                if (denglu.DE_bumeng == 2)
                {
                    ListDesB = ListDesB.Where(s => s.D_zhuang != "5" && s.D_zhuang != "4" && s.D_zhuang != "-99" && s.D_zhuang != "1").ToList();
                }
                var HH = ListDesB.Count().ToString();
                return Content(HH);
            }
            return View();

        }
        public ActionResult Add_log(string DTon, string RZ_bian = null, int state = 0, string path = null, int number = -99)
        {
            if (DTon != null)
            {
                var Listlog = FC.find_bz(DTon);
                ViewBag.Listlog = Listlog;
                Session["names_RZ"] = DTon;

                Session["name_xmfqr"] = db.Applications.Where(x => x.AP_bian == DTon).First().AP_ren;

            }
            if (state == 1)
            {
                var Listlog = FC.find_bz(RZ_bian);
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(Listlog, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 2)
            {
                int rows = FC.find_Design(number);
                string index = "删除" + rows + "条";
                return Json(index);
            }
            else if (state == 3)
            {
                var listdes = FC.find_Design(RZ_bian);
                var list = from s in listdes
                           select new { s.DE_id, De_shijian = s == null ? "" : s.De_shijian, De_ren = s == null ? "暂无" : s.De_ren, DE_Slong = s == null ? "" : s.DE_Slong, De_dizhi = s == null ? "" : s.De_dizhi, DE_tuiLei = s == null ? "" : s.DE_tuiLei };
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(list, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 4)
            {
                var ListDesB = FC.find_Design_liy(number);
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(ListDesB, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 5)
            {
                var ListDesB = FC.find_SJBZ(RZ_bian, number);
                var temp = from a in ListDesB
                           select new { a.SJ_BZ, a.SJR_id, a.SJ_ZT, a.SJ_id, a.SJ_Bian };
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(ListDesB, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 6)
            {
                var list = db.BOMini.Where(x => x.BOM2_bian == RZ_bian).ToList();
                var temp = from a in list
                           select new { a.BOM2_id, a.BOM2_wuLiu };
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(temp, settings);

                return Content(jsongStr, "application/json");
            }
            else if (state == 7)
            {
                int list = db.ShejinBeiZhu.Where(x => x.SJ_Bian == RZ_bian).Count();
                int list2 = db.ShejinBeiZhu.Where(s => s.SJ_Bian == RZ_bian && s.SJ_ZT == "完成").Count();
                if (list2 == list)
                {
                    return Json("全部提交");
                }
                else
                {
                    return Json("未提交");
                }
            }
            return View();
        }
        public ActionResult Download_file(string path)
        {
            if (path != "" || path != null)
            {
                try
                {
                    var lujing = path;
                    var text = lujing;
                    var parts = text.Split('\\');
                    var lastElement = parts[parts.Length - 1];

                    FileStream fs = new FileStream(path, FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];   //以字符流的形式下载文件
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.Charset = "UTF-8";
                    Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                    Response.ContentType = "application/octet-stream";  //通知浏览器下载文件而不是打开

                    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(lastElement));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    Response.End();
                    return new EmptyResult();
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return View();
        }
        public ActionResult AddLogs(BeiZhu beiZhu)
        {
            int rows = AC.Addlogs(beiZhu);
            string message = rows > 0 ? "添加成功" : "添加失败";
            return Content(message, "text / plain");
        }

        public ActionResult Contracts_statement(int state = 0, int BB_WT_id = -99, string BB_WT_sqdh = null, string BB_WT_dj = null, string BB_WT_zt = null, string BB_WT_xmmc = null, string cong = null, string dao = null, int TNt = 0)
        {
            if (state == 1)
            {
                var deslist = FC.find_Contracts(BB_WT_id, BB_WT_sqdh, BB_WT_dj, BB_WT_zt, BB_WT_xmmc, cong, dao);
                foreach (var item in deslist)
                {
                    var temp = "";
                    if (item.D_zhuang == "5")
                    {
                        temp = "项目完成";
                    }
                    else if (item.D_zhuang == "4")
                    {
                        temp = "设计完成";
                    }
                    else if (item.D_zhuang == "3")
                    {
                        temp = "设计中";
                    }
                    else if (item.D_zhuang == "2")
                    {
                        temp = "待分配";
                    }
                    else if (item.D_zhuang == "1")
                    {
                        temp = "待完善";
                    }
                    else
                    {
                        temp = "项目结算";
                    }
                    item.D_JL = temp;
                }

                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(deslist, settings);
                return Content(jsongStr, "text/json");
            }
            if (state == 2)
            {
                var Listlog = FC.find_bz(BB_WT_sqdh);
                JsonSerializerSettings settings = new JsonSerializerSettings();
                string jsongStr = JsonConvert.SerializeObject(Listlog, settings);
                return Content(jsongStr, "application/json");
            }

            return View();
        }

        public ActionResult DrawingLibrary(int state = 0, string bian = null, int hydl = 0, int hyxl = 0, string bzpl = null, string tzlb = null, string bzwmc = null, int TNT = 0, string Gunaj = "")
        {
            ViewBag.ic = db.IndustryCategory.ToList();

            if (state == 1)
            {
                var des = FC.find_Con(bian, hydl, hyxl, bzpl, tzlb, bzwmc, Gunaj);
                //var bom = db.BOMini.ToList();
                des = des.Skip(20 * TNT).Take(20).ToList();
                var sjidn = from a in des
                            join b in db.BOMini on a.bom_id equals b.BOM2_liao into J
                            from b in J.DefaultIfEmpty()
                            select new { a.DE_id, a.De_dizhi, a.De_shijian, a.De_ren, a.DE_shen, a.bom_id, a.DE_JDR, a.DE_Slong, a.DE_wenjain, HD = a.IndustryCategory == null ? "" : a.IndustryCategory.ic_name, HX = a.IndustrySubcategory == null ? "" : a.IndustrySubcategory.isu_name, a.DE_BB, a.DE_bzw, a.DE_bzpl, a.DE_tzlb, a.DE_TZname, HU = b == null ? "" : b.BOM2_wuLiu };
                JsonSerializerSettings settings = new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    Formatting = Formatting.Indented
                };
                string jsongStr = JsonConvert.SerializeObject(sjidn, settings);
                return Content(jsongStr, "application/json");
            }
            if (state == 2)
            {
                var des = FC.find_Con(bian, hydl, hyxl, bzpl, tzlb, bzwmc, Gunaj);
                var jsongStr = des.Count().ToString();
                return Content(jsongStr, "application/json");
            }
            return View();
        }

        public ActionResult DownloadExcel(List<Designdraw> Designdraws, int state = 0, string excelName = null, int WT_CD = 0, string Employee_path = null)
        {
            try
            {
                if (state == 1)
                {
                    ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                    using (ExcelPackage excel = new ExcelPackage())
                    {
                        // 添加工作表
                        var worksheet = excel.Workbook.Worksheets.Add("Sheet1");
                        // 写入数据

                        worksheet.Cells[1, 1].Value = "编号";
                        worksheet.Cells[1, 2].Value = "任务单号";
                        worksheet.Cells[1, 3].Value = "接单人";
                        worksheet.Cells[1, 4].Value = "接单审核人";
                        worksheet.Cells[1, 5].Value = "客户名称";
                        worksheet.Cells[1, 6].Value = "产品名称";
                        worksheet.Cells[1, 7].Value = "项目价值";
                        worksheet.Cells[1, 8].Value = "等级";
                        worksheet.Cells[1, 9].Value = "申请日期";
                        worksheet.Cells[1, 10].Value = "设计完成时间";
                        worksheet.Cells[1, 11].Value = "要求完成时间";
                        worksheet.Cells[1, 12].Value = "设计信息";
                        worksheet.Cells[1, 13].Value = "设计要求";
                        worksheet.Cells[1, 14].Value = "客户需求&项目进展";
                        worksheet.Cells[1, 15].Value = "销售确认时间";
                        worksheet.Cells[1, 16].Value = "设计耗时";
                        worksheet.Cells[1, 17].Value = "审核记录";//
                        worksheet.Cells[1, 18].Value = "审核时间";//
                        worksheet.Cells[1, 19].Value = "项目负责人";
                        worksheet.Cells[1, 20].Value = "申请人";
                        worksheet.Cells[1, 21].Value = "状态";
                        worksheet.Cells[1, 22].Value = "任务单类型";
                        worksheet.Cells[1, 23].Value = "任务完成审核";
                        worksheet.Cells[1, 24].Value = "设计类别";
                        worksheet.Cells[1, 25].Value = "项目附件";//
                        worksheet.Cells[1, 26].Value = "项目进展状态";//
                        worksheet.Row(1).Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                        worksheet.Row(1).Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;

                        int i = 2;

                        //worksheet.Cells[1, 13].Value = "产品重量";
                        //worksheet.Cells[1, 14].Value = "堆叠说明";
                        //worksheet.Cells[1, 15].Value = "其他信息";
                        //worksheet.Cells[1, 16].Value = "运输方式";
                        //worksheet.Cells[1, 17].Value = "包装类型";
                        //worksheet.Cells[1, 18].Value = "防护要求";
                        //worksheet.Cells[1, 19].Value = "其他要求";
                        //worksheet.Cells[1, 20].Value = "标准要求";
                        foreach (Designdraw des in Designdraws)
                        {
                            string khxq = "";
                            string sherji = "";
                            string sss = "";
                            int zhs = 0;
                            var list = db.Design.Where(x => x.DE_shen == des.D_Ton && x.DE_tuiLei == "通过" && x.DE_Slong != null).ToList();
                            var listt2 = db.ShejinBeiZhu.Where(x => x.SJ_Bian == des.D_Ton).ToList();
                            var app = db.Applications.Where(x => x.AP_bian == des.D_Ton).FirstOrDefault();
                            var listbz = db.BeiZhu.Where(x => x.B_Bian == des.D_Ton).ToList();
                            listbz = listbz.OrderByDescending(x => x.B_id).ToList();
                            string skf = "";
                            //审核记录
                            var JL = "";
                            var SHTime = 0.0;
                            foreach (var item in list)
                            {
                                JL += "" + item.De_ren + ":\n\t\t 图纸审核说明：" + item.DZ_Fnajm + "\n";
                                bool result01 = decimal.TryParse(item.DZ_ShTIme, out decimal targetVal01);
                                var Times = "0";
                                if (result01)
                                {
                                    Times = item.DZ_ShTIme == null || item.DZ_ShTIme == "" ? "0" : item.DZ_ShTIme;
                                }
                                SHTime += double.Parse(Times);
                            }
                            foreach (BeiZhu d in listbz)
                            {
                                skf += d.B_Date + " " + d.B_BR + ":" + d.B_bei + "\n";
                            }
                            foreach (ShejinBeiZhu sj in listt2)
                            {
                                if (sss == "")
                                {
                                    sss = sj.Dengli.DE_nae;
                                }
                                else
                                {
                                    sss += "/" + sj.Dengli.DE_nae;
                                }
                            }
                            var list2 = list.GroupBy(a => a.De_ren).Select(g => new
                            {
                                valeu = g.Key,
                                Sum = g.Sum(a => int.Parse(a.DE_Slong))
                            }).ToList();
                            double st = 0.0;
                            foreach (var des2 in list2)
                            {
                                st += des2.Sum;
                            }
                            if (des.D_PW != null)
                            {
                                khxq += "产品重量:" + des.D_PW + "\n";
                            }
                            if (des.D_SI != null)
                            {
                                khxq += "堆叠说明:" + des.D_SI + "\n";
                            }
                            //移出
                            if (des.D_OI == null || des.D_OI == "")
                            {
                                des.D_OI = "";
                            }
                            if (des.D_MOF != null)
                            {
                                khxq += "运输方式:" + des.D_MOF + "\n";
                            }
                            if (des.D_PT != null)
                            {
                                khxq += "包装类型:" + des.D_PT + "\n";
                            }
                            if (des.D_PR != null)
                            {
                                khxq += "防护要求:" + des.D_PR + "\n";
                            }
                            if (des.D_OR != null)
                            {
                                khxq += "其他要求或信息:" + des.D_OR + "\n";
                            }
                            if (des.D_SR != null)
                            {
                                khxq += "标准要求:" + des.D_SR + "\n";
                            }
                            string zt = "";

                            if (des.D_id == null)
                            {
                                des.D_id = 0;
                            }
                            if (des.D_Ton == null)
                            {
                                des.D_Ton = "";
                            }
                            if (des.D_AppRevi == null || des.D_AppRevi == "null")
                            {
                                des.D_AppRevi = "";
                            }
                            if (des.D_CN == null || des.D_CN == "null")
                            {
                                des.D_CN = "";
                            }
                            if (des.D_PN == null)
                            {
                                des.D_PN = "";
                            }
                            if (app.App_Jz == null)
                            {
                                app.App_Jz = "";
                            }
                            if (des.D_LV == null || des.D_LV == "null")
                            {
                                des.D_LV = "";
                            }
                            if (des.D_CD == null || des.D_CD == "null")
                            {
                                des.D_CD = "";
                            }
                            if (des.D_reDate == null || des.D_reDate == "null")
                            {
                                des.D_reDate = "";
                            }
                            if (app.App_fzr == null || app.App_fzr == "null")
                            {
                                app.App_fzr = "";
                            }
                            if (app.App_xmzt == null || app.App_xmzt == "null")
                            {
                                app.App_xmzt = "";
                            }
                            if (des.D_take == null || des.D_take == "null")
                            {
                                des.D_take = "";
                            }
                            if (des.D_TCA == null || des.D_TCA == "null")
                            {
                                des.D_TCA = "";
                            }
                            if (des.D_DE == null || des.D_DE == "null")
                            {
                                des.D_DE = "";
                            }
                            if (des.D_PA == null || des.D_PA == "null")
                            {
                                des.D_PA = "";
                            }

                            sherji += "设计总用时:" + zhs + "分钟";
                            int index = 1;
                            worksheet.Cells[i, index].Value = des.D_id;//id
                            index++;
                            worksheet.Cells[i, index].Value = des.D_Ton;//申请单号
                            index++;
                            worksheet.Cells[i, index].Value = sss;//接单人
                            index++;
                            worksheet.Cells[i, index].Value = des.D_AppRevi;//接单审核人
                            index++;
                            worksheet.Cells[i, index].Value = des.D_CN;//客户
                            index++;
                            worksheet.Cells[i, index].Value = des.D_PN;//项目名称
                            index++;
                            worksheet.Cells[i, index].Value = app.App_Jz;//项目价值
                            index++;
                            worksheet.Cells[i, index].Value = des.D_LV;//等级
                            index++;
                            worksheet.Cells[i, index].Value = des.D_Applic == null || des.D_Applic == "" ? DateTime.Parse("1979-1-1") : DateTime.Parse(des.D_Applic);//申请日期
                            worksheet.Cells[i, index].Style.Numberformat.Format = "yyyy/mm/dd";
                            index++;
                            worksheet.Cells[i, index].Value = des.DFToDate;//设计完成时间
                            index++;
                            worksheet.Cells[i, index].Value = des.D_reDate == null || des.D_reDate == "" ? DateTime.Parse("1979-1-1") : DateTime.Parse(des.D_reDate);//要求完成日期
                            worksheet.Cells[i, index].Style.Numberformat.Format = "yyyy/mm/dd";
                            index++;
                            worksheet.Cells[i, index].Value = khxq;//客户需求
                            worksheet.Cells[i, index].Style.WrapText = true;
                            index++;
                            worksheet.Cells[i, index].Value = des.D_OI;//设计要求
                            worksheet.Cells[i, index].Style.WrapText = true;
                            index++;
                            worksheet.Cells[i, index].Value = skf;//日志
                            worksheet.Cells[i, index].Style.WrapText = true;
                            index++;
                            worksheet.Cells[i, index].Value = des.D_CD == null || des.D_CD == "" ? DateTime.Parse("1999-1-1") : DateTime.Parse(des.D_CD);//完成时间
                            worksheet.Cells[i, index].Style.Numberformat.Format = "yyyy/mm/dd";
                            index++;
                            worksheet.Cells[i, index].Value = st;//设计耗时
                            index++;
                            worksheet.Cells[i, index].Value = JL;//审核记录
                            worksheet.Cells[i, index].Style.WrapText = true;
                            index++;
                            worksheet.Cells[i, index].Value = SHTime;//审核记录
                            index++;
                            worksheet.Cells[i, index].Value = app.App_fzr;//负责人
                            index++;
                            worksheet.Cells[i, index].Value = des.D_App;//发起人
                            index++;
                            worksheet.Cells[i, index].Value = app.App_xmzt;//项目状态
                            index++;

                            worksheet.Cells[i, index].Value = des.D_take;//项目类型
                            index++;
                            worksheet.Cells[i, index].Value = des.D_TCA;//完成审核
                            index++;
                            worksheet.Cells[i, index].Value = des.D_DE;//设计类别
                            index++;
                            worksheet.Cells[i, index].Value = des.D_PA;//项目附件
                            index++;
                            worksheet.Cells[i, index].Value = des.D_zhuang;//项目附件

                            worksheet.Row(i).Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
                            worksheet.Row(i).Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;

                            i++;
                        }
                        worksheet.Cells["A:Z"].AutoFitColumns();
                        worksheet.Column(11).Width = 40;
                        worksheet.Column(12).Width = 40;
                        worksheet.Column(13).Width = 40;
                        worksheet.Column(23).Width = 60;
                        string path = "";
                        path = Server.MapPath("~/Files/");
                        string Name = excelName + ".xlsx";
                        // 确保目录存在  
                        Directory.CreateDirectory(path);

                        // 生成唯一的文件名（这里只是简单示例，你可能需要更复杂的唯一性逻辑）  
                        string fileName = Path.GetFileNameWithoutExtension(Name) + "_" + Guid.NewGuid() + Path.GetExtension(Name);

                        // 保存文件到服务器  
                        string filePath = Path.Combine(path, fileName);
                        excel.SaveAs(filePath);
                        return Json(filePath);

                    }
                }
            }
            catch (Exception ex)
            {
                var hu = ex.Message;
            }

            return View();
        }

        [HttpPost]
        public JsonResult AddNdardo(HttpPostedFileBase file)
        {
            string path = "";
            if (file != null && file.ContentLength > 0)
            {
                string filePath;
                HUNFF(file, out path, out filePath);

                return Json(filePath);
            }
            else
            {
                // 返回失败消息  
                return Json(new { success = false, message = "没有文件被上传或者文件大小为0." });
            }

            return Json(new { success = false, });
        }

        private void HUNFF(HttpPostedFileBase file, out string path, out string filePath)
        {
            // 指定保存文件的路径（服务器上的实际路径）  
            path = Server.MapPath("~/Files/");
            // 确保目录存在  
            Directory.CreateDirectory(path);

            // 生成唯一的文件名（这里只是简单示例，你可能需要更复杂的唯一性逻辑）  
            //文本替换
            var CHUNF = Path.GetFileNameWithoutExtension(file.FileName).Split(new char[7] { '+', '&', '@', '%', '|', '#', '/' });
            var shun = string.Join("", CHUNF);
            string fileName = shun + "_" + Guid.NewGuid() + Path.GetExtension(file.FileName);

            // 保存文件到服务器  
            filePath = Path.Combine(path, fileName);
            file.SaveAs(filePath);
        }

        public ActionResult chanegSPR(List<ShejinBeiZhu> shejinBeiZhus)
        {
            foreach (ShejinBeiZhu a in shejinBeiZhus)
            {
                ShejinBeiZhu she = db.ShejinBeiZhu.Where(x => x.SJR_id == a.SJR_id && x.SJ_Bian == a.SJ_Bian).FirstOrDefault();
                she.SJ_ZT = a.SJ_ZT;
                int temp = db.SaveChanges();
                string powasd = temp > 0 ? "添加成功" : "添加失败";
                return Json(powasd);
            }
            return View();
        }
        public JsonResult adddes(List<Design> des)
        {
            string all = "";
            try
            {
                int index = 0;
                int row = 0;
                foreach (Design a in des)
                {
                    using (LDbaseEntities db = new LDbaseEntities())
                    {
                        if (a.DE_id != 0)
                        {
                            Design v = db.Design.Where(x => x.DE_id == a.DE_id).FirstOrDefault();

                            v.De_dizhi = a.De_dizhi;
                            v.DE_Slong = a.DE_Slong;
                            v.De_shijian = a.De_shijian;
                            v.DE_tuiLei = a.DE_tuiLei;
                            v.DE_BB = a.DE_BB;
                            v.DE_TZname = a.DE_TZname;
                            row += db.SaveChanges();
                        }
                        else
                        {
                            if (des == null)
                            {
                                des = new List<Design>();
                            }
                            db.Design.Add(a);
                            index += db.SaveChanges();
                        }
                    }
                }
                all = "新增:" + index + "条,修改:" + row + "条";
            }
            catch (Exception ex)
            {
                var allting = ex.Message;
                all = "";
            }

            return Json(all);
        }
        public JsonResult UpdateDes(List<Design> des)
        {
            string all = "";
            try
            {
                int index = 0;
                int row = 0;
                foreach (Design a in des)
                {
                    if (a.DE_id != 0)
                    {
                        Design v = db.Design.Where(x => x.DE_id == a.DE_id).FirstOrDefault();
                        v.DE_h1_id = a.DE_h1_id;
                        v.DE_h2_id = a.DE_h2_id;
                        v.DE_bzw = a.DE_bzw;
                        v.DE_bzpl = a.DE_bzpl;
                        v.DE_tzlb = v.DE_tzlb;
                        db.Entry(v).State = EntityState.Modified;
                        row += db.SaveChanges();
                    }
                }
                all = "修改:" + row + "条";
            }
            catch (Exception ex)
            {
                var allting = ex.Message;
                all = "";
            }

            return Json(all);
        }
        public JsonResult Addfr(List<Freight> des)
        {
            int index = 0;
            foreach (Freight a in des)
            {
                using (LDbaseEntities db = new LDbaseEntities())
                {
                    if (des == null)
                    {
                        des = new List<Freight>();
                    }
                    db.Freight.Add(a);
                    index += db.SaveChanges();
                }
            }
            string all = "新增:" + index + "条";
            return Json(all);
        }
        public JsonResult Modify_INF_zhuang(List<Design> modle)
        {
            int rows = 0;
            foreach (Design i in modle)
            {
                if (modle == null)
                {
                    modle = new List<Design>();
                }
                Design inf = new Design()
                {
                    DE_id = i.DE_id,
                    DE_JDR = i.DE_JDR,
                    DE_tuiLei = i.DE_tuiLei,
                    DE_wenjain = i.DE_wenjain,
                };
                rows += MC.Changedes(inf);
                Design design = db.Design.Where(a => a.DE_id == i.DE_id).FirstOrDefault();
                Dengli dengli = db.Dengli.Where(b => b.DE_nae == design.De_ren).FirstOrDefault();
                ShejinBeiZhu sjb = db.ShejinBeiZhu.Where(x => x.SJ_Bian == design.DE_shen && x.SJR_id == dengli.DE_ID).FirstOrDefault();
                sjb.SJ_ZT = "驳回";
                db.SaveChanges();
            }
            string message = "修改" + rows + "条";
            return Json(message);
        }
        public JsonResult Modify_INF_zhuang2(List<Design> modle)
        {
            int rows = 0;
            foreach (Design i in modle)
            {
                if (modle == null)
                {
                    modle = new List<Design>();
                }
                Design inf = new Design()
                {
                    DE_id = i.DE_id,
                    DE_JDR = i.DE_JDR,
                    DE_tuiLei = i.DE_tuiLei,
                    DZ_Fnajm = i.DZ_Fnajm,
                    DZ_ShTIme = i.DZ_ShTIme
                };
                rows += MC.Changedes3(inf);
            }
            string message = "修改" + rows + "条";
            return Json(message);

        }
        public JsonResult Modify_des_zhuang(List<Designdraw> modle)
        {
            int rows = 0;
            foreach (Designdraw i in modle)
            {
                if (modle == null)
                {
                    modle = new List<Designdraw>();
                }
                Designdraw inf = new Designdraw()
                {
                    D_Ton = i.D_Ton,
                    D_zhuang = i.D_zhuang,
                };
                rows += MC.Changedes2(inf);
            }

            string message = "修改" + rows + "条";
            return Json(message);

        }
        public JsonResult Modify_des_zhuang245(List<Designdraw> modle)
        {
            int rows = 0;
            int cols = 0;
            string num = "0";
            string messs = "";
            foreach (Designdraw i in modle)
            {
                Applications applications = db.Applications.Where(x => x.AP_bian == i.D_Ton).FirstOrDefault();
                Designdraw des = db.Designdraw.Where(x => x.D_Ton == i.D_Ton).FirstOrDefault();
                if (applications.App_bu == "-99")
                {
                    if (des != null)
                    {
                        des.D_zhuang = des.D_JL;
                        des.D_JL = null;
                    }
                    applications.App_bu = applications.App_JL;
                    applications.App_JL = null;
                    rows = db.SaveChanges();
                    if (rows > 0)
                    {
                        messs = "项目重启成功";
                    }
                }
                else
                {
                    messs = "项目没有结束，无需重启";
                }
            }

            return Json(messs);
        }

        public JsonResult Modify_des_zhuang2(List<Designdraw> modle)
        {
            int rows = 0;
            int cols = 0;
            string num = "0";
            string messs = "";
            foreach (Designdraw i in modle)
            {
                Applications applications = db.Applications.Where(x => x.AP_bian == i.D_Ton).FirstOrDefault();
                Designdraw des = db.Designdraw.Where(x => x.D_Ton == i.D_Ton).FirstOrDefault();

                if (modle == null)
                {
                    modle = new List<Designdraw>();
                }
                string index = FC.fing_bushu(i.D_Ton);
                if (index == "3")
                {
                    num = "-99";
                }
                else
                {
                    num = "2";
                    if (i.D_zhuang == "-99")
                    {
                        num = "-99";
                    }
                }
                if (num == "2")
                {
                    Applications app = new Applications()
                    {

                        AP_bian = i.D_Ton,
                        App_bu = num

                    };
                    cols += MC.Changeapp(app);
                }
                else
                {
                    Applications app = new Applications()
                    {

                        App_JL = applications.App_bu,
                        AP_bian = i.D_Ton,
                        App_bu = num

                    };
                    cols += MC.Changeapp(app);
                }
                if (des != null)
                {
                    if (i.D_zhuang == "-99")
                    {
                        Designdraw inf = new Designdraw()
                        {
                            D_Ton = i.D_Ton,
                            D_zhuang = i.D_zhuang,
                            D_CD = i.D_CD,
                            D_TCA = i.D_TCA,
                            D_JL = des.D_zhuang

                        };
                        rows += MC.Changedes2(inf);
                    }
                    else
                    {
                        Designdraw inf = new Designdraw()
                        {
                            D_Ton = i.D_Ton,
                            D_zhuang = i.D_zhuang,
                            D_CD = i.D_CD,
                            D_TCA = i.D_TCA
                        };
                        rows += MC.Changedes2(inf);
                    }

                }

                var bainas = i.D_Ton;
                var sjind = db.Applications.FirstOrDefault(s => s.AP_bian == bainas);

                if (i.D_zhuang == "5")
                {
                    if (sjind.APP_she == "S")
                    {
                        messs = "项目完成";
                    }
                    else if (sjind.APP_she == "Y")
                    {
                        messs = "项目继续";
                    }
                }
                else if (i.D_zhuang == "-99")
                {
                    messs = "项目结束";
                }

            }
            return Json(messs);
        }

        public JsonResult Modify_des_Slong(List<Design> modle)
        {
            int rows = 0;
            foreach (Design i in modle)
            {
                if (modle == null)
                {
                    modle = new List<Design>();
                }
                Design inf = new Design()
                {
                    DE_id = i.DE_id,
                    DE_Slong = i.DE_Slong
                };
                rows += MC.Changedestime(inf);
            }

            string message = "修改" + rows + "条";
            return Json(message);

        }
        public JsonResult ADDSJBZ(List<ShejinBeiZhu> des)
        {
            int index = 0;
            var bian = "";
            var shun = des[0].SJ_Bian;
            var shuj = db.ShejinBeiZhu.Where(s => s.SJ_Bian == shun).ToList();
            var L = "";
            if (shuj.Count > 0)
            {
                var DJL = shuj.Select(s => int.Parse(s.SJ_JL)).Max();//存在记录记录最大值
                L = (DJL + 1).ToString();
            }
            else
            {
                L = "0";
            }
            foreach (ShejinBeiZhu a in des)
            {
                using (LDbaseEntities dbf = new LDbaseEntities())
                {
                    if (des == null)
                    {
                        des = new List<ShejinBeiZhu>();
                    }
                    if (a.SJ_JL == "" || a.SJ_JL == null)
                    {
                        a.SJ_JL = L;
                    }
                    dbf.ShejinBeiZhu.Add(a);
                    index += dbf.SaveChanges();
                }
                bian = a.SJ_Bian;
            }
            Designdraw designdraw = db.Designdraw.Where(x => x.D_Ton == shun).FirstOrDefault();
            designdraw.D_zhuang = "3";
            int shu = db.SaveChanges();
            string all = "新增:" + index + "条";
            return Json(all);
        }
        public JsonResult chaneSJBZ(List<ShejinBeiZhu> des)
        {
            int index = 0;
            foreach (ShejinBeiZhu a in des)
            {
                ShejinBeiZhu beiZhu = db.ShejinBeiZhu.Where(x => x.SJR_id == a.SJR_id && x.SJ_Bian == a.SJ_Bian).FirstOrDefault();
                beiZhu.SJ_ZT = a.SJ_ZT;
                beiZhu.SJ_QTY = beiZhu.SJ_QTY == null || beiZhu.SJ_QTY == 0 ? 1 : beiZhu.SJ_QTY + 1;
                index = db.SaveChanges();
            }

            string all = "修改:" + index + "条";
            return Json(all);
        }
        public ActionResult SendEmails()
        {
            // 设置发件人邮箱账号和授权码（不是密码）  
            var fromEmail = new MailAddress("18118449109@163.com", "18118449109");
            var fromPassword = "HBNCQUPLVDKZKQBH"; // 不是邮箱密码，而是网易邮箱的授权码  

            // 设置收件人邮箱账号和姓名  
            var toEmail = new MailAddress("2857651041@qq.com", "开位master咕哒");

            // 创建邮件正文内容  
            var body = "这是一封来自163邮箱的测试邮件！";

            // 创建邮件主题和正文  
            var mailMessage = new MailMessage(fromEmail, toEmail)
            {
                Subject = "测试邮件",
                Body = body,
                IsBodyHtml = false // 如果需要HTML格式，请设置为true  
            };

            // 创建SmtpClient对象并配置服务器信息  
            var smtpClient = new SmtpClient("smtp.163.com", 587) // SMTP服务器地址和端口号  
            {
                EnableSsl = true, // 如果SMTP服务器需要SSL，则设置为true  
                DeliveryMethod = SmtpDeliveryMethod.Network, // 使用网络发送邮件的方式  
                UseDefaultCredentials = false, // 使用默认凭据时设置为false  
                Credentials = new NetworkCredential(fromEmail.Address, fromPassword) // 发送者的邮箱账号和授权码（不是密码）  
            };
            try
            {
                // 发送邮件  
                smtpClient.Send(mailMessage);
                return Json("邮件发送成功！"); // 返回成功的响应或重定向到其他页面  
            }
            catch (Exception ex)
            {
                // 处理异常或记录错误日志  
                return Json("邮件发送失败：" + ex.Message); // 返回失败的响应或重定向到错误页面  
            }
        }

        #region 批量下载文件
        public ActionResult DownloadFile(string list1)
        {
            List<Design> list = new List<Design>();
            string filePath = Server.MapPath("~/Files/");
            var HUSn = list1.Split(',');
            for (int i = 0; i < HUSn.Length; i++)
            {
                int HNJ = 0;
                if (HUSn[i] == "")
                {
                    continue;
                }
                else
                {
                    HNJ = int.Parse(HUSn[i]);
                }
                var shu = db.Design.Where(s => s.DE_id == HNJ).FirstOrDefault();
                list.Add(shu);
            }
            Dictionary<string, byte[]> fileDataDict = new Dictionary<string, byte[]>();

            foreach (var fileName in list)
            {
                string fullPath = fileName.De_dizhi;

                if (!System.IO.File.Exists(fullPath)) continue;
                byte[] bytes;
                using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
                {
                    bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                }
                fileDataDict[fileName.DE_TZname] = bytes;
            }
            // 压缩
            using (MemoryStream ms = new MemoryStream())
            {
                PackageManyZip(fileDataDict, ms);
                byte[] zipBytes = ms.ToArray();
                // 返回 ZIP 文件
                string zipName = DateTime.Today.ToString("yyyy-MM-dd") + ".zip";
                Response.ContentType = "application/octet-stream";  //通知浏览器下载文件而不是打开
                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(zipName,System.Text.Encoding.UTF8));
                Response.BinaryWrite(zipBytes);
                Response.Flush();
                Response.End();
            }
            return View();
        }

        public static void PackageManyZip(Dictionary<string, byte[]> fileDataDict, MemoryStream outputStream)
        {
            byte[] buffer = new byte[1024*1024*10];
            using (ZipOutputStream zipStream = new ZipOutputStream(outputStream))
            {
                zipStream.SetLevel(6);//最高压缩登记
                foreach (var kv in fileDataDict)
                {
                    string fileName = kv.Key;
                    byte[] fileData = kv.Value;
                    zipStream.PutNextEntry(new ZipEntry(fileName));
                    using (MemoryStream memoryStream = new MemoryStream(fileData))
                    {
                        int readCount;
                        while ((readCount = memoryStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            zipStream.Write(buffer, 0, readCount);
                        }
                    }
                    zipStream.CloseEntry();
                }
                zipStream.Finish();
            }
            // 不需要重置 outputStream 的位置，因为它将在外部被使用
        }
        #endregion

    }
}